package cn.platform.controller;

import cn.platform.entity.Comment;
import cn.platform.request.CommentRequest;
import cn.platform.request.CommentViewRequest;
import cn.platform.response.AResponse;
import cn.platform.service.CommentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@CrossOrigin(maxAge = 3600) //允许跨域请求
@Controller
@RequestMapping("/api/chat")
public class ChatCommentController {

    @Resource
    CommentService commentService;

    /**
     * 返回前端展示所需数据
     */
    @RequestMapping("/listView")
    @ResponseBody
    public AResponse listCommentView(@RequestBody CommentViewRequest req) {
        return commentService.listCommentView(req);
    }

    /**
     * 暂时保留
     */
    @RequestMapping("/list")
    @ResponseBody
    public AResponse listComment(@RequestBody CommentRequest req) {
        return commentService.listComment(req);
    }

    /**
     * 发送评论
     */
    @RequestMapping("/send")
    @ResponseBody
    public AResponse insertComment(@RequestBody Comment req){
        return commentService.insertComment(req);
    }

//    评论没有更新的必要，正常情况发送了就不能更新，只能删除
//    @RequestMapping("/update")
//    @ResponseBody
//    public AResponse updateComment(@RequestBody Comment req){
//        return commentService.updateComment(req);
//    }

    /**
     * 删除评论
     */
    @RequestMapping("/delete")
    @ResponseBody
    public AResponse deleteComment(@RequestParam("id") int id){
        return commentService.deleteComment(id);
    }
}
